(function ($) {

    window.JPop = function () {
        let html = `<div class='jtable-cz-pop' id="jpop_div"></div>`

        return {
            dialogDel(options) {
                if ($('body #jpop_div').attr('class') === 'jtable-cz-pop') {
                    $('#jpop_div').fadeIn()
                } else {
                    $('body').append(html)
                }
                $('#jpop_div').css('background','#041d32')
                $('#jpop_div').addClass('jpop-cz-contain')
                if (options.operate) {
                    let operatehtml = `
                        <div class='jpop-title'>提示</div>
                        <div class='jpop-msg'>${options.msg}</div>
                        <div class='jpop-btn' id='jpop_btn'><span class='jpop-btn-yes'>确定</span><span class='jpop-btn-no'>取消</span></div></div>`
                    $('#jpop_div').append(operatehtml)

                    $('#jpop_btn').find('span').click(function () { 
                        $('#jpop_div').fadeOut()
                        setTimeout(function() { 
                            $("#jpop_div").html('');
                            $('#jpop_div').removeClass('jpop-cz-contain')
                        }, 500);
                        
                    });
                    return {
                        on: function (callback) {
                            if (callback && callback instanceof Function) {
                                $('#jpop_btn').find('.jpop-btn-yes').click(function () { 
                                    callback(true); 
                                });
                            }
                        },
                        hide: function (callback) {
                            if (callback && callback instanceof Function) {
                                $('#jpop_btn').find('.jpop-btn-no').click(function () { 
                                });
                            }
                        }
                    }
                } else {
                    $('#jpop_div').html('')
                }
            },
            alert(options) {
                $("#jpop_div").html('');
                options.msg = options.msg || '操作成功'
                if ($('body #jpop_div').attr('class') === 'jtable-cz-pop') {
                    $('#jpop_div').fadeIn()
                } else {
                    $('body').append(html)
                }
                if (options.type === 'success') {
                    $('#jpop_div').css('background','#34959c')
                    $("#jpop_div").append(`<i class="iconfont" style="margin-right:10px;">&#xe60d;</i>`)
                } else if (options.type === 'error') {
                    $('#jpop_div').css('background','#ff5656')
                    $("#jpop_div").append(`<i class="iconfont" style="margin-right:10px;">&#xe648;</i>`)
                } else {
                    $('#jpop_div').css('background','#5489e7')
                    $("#jpop_div").append(`<i class="iconfont" style="margin-right:10px;">&#xe64a;</i>`)
                }
                $('#jpop_div').append(`<span>${options.msg}</span>`)
                setTimeout(function() { 
                    $('#jpop_div').fadeOut();
                    setTimeout(() => {
                        $("#jpop_div").html('');
                    },500)
                }, 1500);
            }
        }
    }();
})(jQuery);

